package com.example.mysafegarud;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class myAdatper extends BaseAdapter {
    Context context;
    int[] img = new int[]{R.drawable.safe, R.drawable.app, R.drawable.callmsgsafe, R.drawable.taskmanager, R.drawable.trojan, R.drawable.atools, R.drawable.sysoptimize, R.drawable.netmanager, R.drawable.settings};
    String[] strings = new String[]{"手机防盗", "软件管家", "通讯卫士", "进程管理", "病毒查杀", "高级工具", "缓存清理", "流量监控", "系统设置"};

    public myAdatper(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
//       复用个数
        return img.length;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.layout, parent, false);
            viewHolder=new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) convertView.getTag();
        }
        viewHolder.img.setImageResource(img[position]);
        viewHolder.text.setText(strings[position]);
        return convertView;
    }

    public class ViewHolder {
        public View rootView;
        public ImageView img;
        public TextView text;

        public ViewHolder(View rootView) {
            this.rootView = rootView;
            this.img = (ImageView) rootView.findViewById(R.id.img);
            this.text = (TextView) rootView.findViewById(R.id.text);
        }

    }
}
